package Multithreading.base.匿名线程;

//匿名
public class Anonymous {
    /**
     * 开启线程的三种方式
     * @param args
     */
    public static void main(String[] args) {
        System.out.println("----------第1种---------------");
        // todo 方式一
        Thread thread1 = new Thread(){
            @Override
            public void run() {
                System.out.println("new Thread() 重写run() 创建线程");
            }
        };
        thread1.start();
        // 匿名方式
        new Thread(){
            @Override
            public void run() {
                System.out.println("new Thread() 匿名方式创建线程");
            }
        }.start();

        // TODO 方式二
        System.out.println("----------第2种---------------");
        Runnable runnable = new Runnable() {
            @Override
            public void run() {
                System.out.println("new Runnable 创建一个线程");
            }
        };
        Thread thread2 = new Thread(runnable);
        thread2.start();

        //匿名 Runnable
        Thread thread3 = new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("匿名Runnable 创建一个线程");
            }
        });
        thread3.start();

        System.out.println("----------第3种---------------");
        new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("匿名Thread 匿名 Runnable 创建一个线程");
            }
        }).start();
    }
}
